import Vue from "vue";
import VueRouter from "vue-router";

Vue.use(VueRouter);


import Front from "../layout/Front";
import Last from "../layout/Last";

const routes = [


    //前台
  {
    path:'/',
    name:'front',
    component: Front,
    children:[{
        path: "/",
        name: "Home",
        component: () => import("@/views/Home"),

      },
      //后台
      {
        path:'/admin',
        name:'admin',
        component: () => import("@/views/auth/AdminLogin"),
      },
/*      {
        path: '/last',
        component:Last,
        children:[{

        }]
      },*/
      {
        path: '/last',
        component:Last,
      },
      {
        path: "/register",
        name: "register",
        component: () => import("@/views/auth/Register"),
        meta: { title: "注册" },
      },
      // 登录
      {
        name: "login",
        path: "/login",
        component: () => import("@/views/auth/Login"),
        meta: { title: "登录" },
      },
      // 发布
      {
        name: "post-create",
        path: "/post/create",
        component: () => import("@/views/post/Create"),
        meta: { title: "信息发布", requireAuth: true },
      },
      // 编辑
      {
        name: 'topic-edit',
        path: '/topic/edit/:id',
        component: () => import('@/views/post/Edit'),
        meta: {
          title: '编辑',
          requireAuth: true
        }
      },
      // 详情
      {
        path: "/post/:id",
        name: "post-detail",
        component: () => import("@/views/post/Detail"),
        meta: { title: "详情" },
      },
      //标签
      {
        name: 'tag',
        path: '/tag/:name',
        component: () => import('@/views/tag/Tag'),
        meta: { title: '主题列表' }
      },
      // 检索
      {
        name: 'search',
        path: '/search',
        component: () => import('@/views/Search'),
        meta: { title: '检索' }
      },
      // 用户主页
      {
        name: 'user',
        path: '/member/:username/home',
        component: () => import('@/views/user/Profile'),
        meta: { title: '用户主页' }
      },
      // 用户设置
      {
        name: 'user-setting',
        path: '/member/:username/setting',
        component: () => import('@/views/user/Setting'),
        meta: { title: '设置', requireAuth: true }
      },
      {
        path: "/404",
        name: "404",
        component: () => import("@/views/error/404"),
        meta: { title: "404-NotFound" },
      },
      {
        path: "*",
        redirect: "/404",
        hidden: true,

    }]

  },
];


const originalPush = VueRouter.prototype.push;
//重写了原型上的push方法，统一的处理了错误信息
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch((err) => err);
};
//实例化vueRouter
const router = new VueRouter({
  //去掉url #号
  mode:'history',
  routes,
});

export default router;
